package com.zhdl.network.demotcp.analysis;

import cn.hutool.core.util.HexUtil;
import com.project.command.faq.analysis.ComAnalysis;
import com.project.command.faq.analysis.ComAnalysisData;
import com.project.command.faq.analysis.ComAnalysisResult;
import com.zhdl.network.demotcp.dto.MemoBusResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * MemoBus响应数据解析
 */
@Slf4j
@Service(MemoBusAnalysisImpl.MODBUS_TCP_ANALYSIS)
public class MemoBusAnalysisImpl implements ComAnalysis<MemoBusResp<Short>, List<MemoBusResp<Short>>> {


    public static final String MODBUS_TCP_ANALYSIS = "modbus_tcp";

    @Override
    public ComAnalysisResult<MemoBusResp<Short>> analysisData(ComAnalysisData<List<MemoBusResp<Short>>> data) {
        log.info(data.getBuf().toString());
        return new ComAnalysisResult<>(data.getBuf());
    }

    /**
     * 11 为发送数据
     *
     * @return
     */
    @Override
    public String getHeadAnalysis() {
        return "11";
    }

    @Override
    public byte[] getAfterAnalysis(String cmdStr) {
        return HexUtil.decodeHex((getHeadAnalysis() + cmdStr));
    }
}
